package com.yht.org.service.impl;

import com.yht.basic.util.QueryResult;
import com.yht.org.domain.Employee;
import com.yht.org.domain.Shop;
import com.yht.org.mapper.ShopMapper;
import com.yht.org.query.ShopQuery;
import com.yht.org.service.IShopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional(readOnly = true,propagation = Propagation.SUPPORTS)
public class ShopServiceImpl implements IShopService {
    @Autowired
    private ShopMapper shopMapper;
    @Override
    @Transactional
    public void add(Shop shop) {
        shopMapper.insert(shop);
    }

    @Override
    @Transactional
    public void delete(Long id) {
        shopMapper.delete(id);
    }

    @Override
    @Transactional
    public void update(Shop shop) {
        shopMapper.update(shop);
    }

    @Override
    public Shop findById(Long id) {
        return shopMapper.selectById(id);
    }

    @Override
    public List<Shop> findAll() {
        return shopMapper.selectAll();
    }

    @Override
    public QueryResult<Shop> findByShopQuery(ShopQuery shopQuery) {
        Integer total = shopMapper.selectCount(shopQuery);
        if(total == 0){
            return new QueryResult<>();
        }
        List<Shop> shops = shopMapper.selectByShopQuery(shopQuery);
        QueryResult<Shop> result = new QueryResult<>(total, shops);
        return result;
    }
}
